package com.info.zhiduoduo.repository.mapper.company;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.company.AssessmentReportDto;
import com.info.zhiduoduo.repository.dto.company.EnterpriseScoreListDto;
import com.info.zhiduoduo.repository.entity.company.EnterpriseScore;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 企业评分
 * </p>
 *
 * @author wtt
 * @since 2022/2/11
 */
public interface EnterpriseScoreMapper extends BaseMapper<EnterpriseScore> {

    @Select(" SELECT es.* FROM zdd_enterprise_score es " +
            " WHERE es.compid = #{compid} ")
    AssessmentReportDto AssessmentReport(@Param("compid") int compid);

    @Select("SELECT c.compname,es.total_score,c.compid, " +
            "CASE WHEN es.total_score IS NULL THEN 1 ELSE 2 END AS whetherToScore " +
            "FROM zdd_company c " +
            "LEFT JOIN zdd_enterprise_score es ON es.compid = c.compid " +
            "WHERE c.compname LIKE '%${compname}%' " +
            "AND c.state = 4 " +
            "having IF(#{whetherToScore}=0,1=1,whetherToScore = #{whetherToScore}) " +
            "ORDER BY c.createtime DESC " )
    List<EnterpriseScoreListDto> EnterpriseScoreList(@Param("compname") String compname, @Param("whetherToScore") int whetherToScore);
}
